<template>
	<view class="bg">
		<view class="top_nav_box">
			<view class="title"> 我的 </view>
		</view>
		<view class="header">
			<view class="header_user" @click="login()">
				<view class="header_user_left">
					<view class="header_user_icon"> <img :src="headimg" alt=""> </view>
					<view class="header_user_username"> <span>{{username}}</span> </view>
				</view>
			<!-- 	<view class="header_user_right">
					<img src="../../static/icon/arrow_r_white.png" alt="">
				</view> -->
			</view>
			<view class="header_vip" @tap="goPage(routes.vip)">
				<view class="header_vip_icon">
					<img src="../../static/icon/vip.png" alt="">
				</view>
				<view class="header_vip_text" v-if="vip != 1">
					<view class="header_vip_text_1"> 会员尊享多种特权 </view>
					<view class="header_vip_text_2"> 会员每天免费刷题 </view>
				</view>
				<view class="header_vip_text" v-else>
					<view class="header_vip_text_1"> 您已是vip会员 </view>
					<view class="header_vip_text_2"> 到期时间：9999-12-31 </view>
				</view>
				<view class="header_vip_btn" v-if="vip != 1">
					去激活
					<img src="../../static/icon/arrow_r_1.png" alt="">
				</view>
			</view>
		</view>
		<!-- 
			section部分
			做题数据
			关于我们
			意见反馈
			题库购买【暂时】
		 -->
		<view class="section">
			<view class="section_item" @tap="goPage(routes.about)">
				<view class="section_item_l">
					<img src="../../static/icon/bianji.png" alt="">
					关于我们
				</view>
				<view class="section_item_r">
					<img src="../../static/icon/arrow_r_1.png" alt="">
				</view>
			</view>
			<view class="section_item" @tap="goPage(routes.feedback)">
				<view class="section_item_l">
					<img src="../../static/icon/tip.png" alt="">
					意见反馈
				</view>
				<view class="section_item_r">
					<img src="../../static/icon/arrow_r_1.png" alt="">
				</view>
			</view>
		</view>
		<!-- footer部分 暂定退出账号 -->
		<!-- <view class="footer" @tap="exit()" v-if="loginState == true"> 退出登录 </view> -->
		<!-- 自定义tabber导航栏 -->
		<!-- 	<view class="bottom_nav_box">
			<view class="bottom_nav_box_1" @tap="goIndexPage()">
				<img src="../../static/icon/tiku1.png" alt="">
				<view class="selected_text_color">
					题库
				</view>
			</view>
			<view class="bottom_nav_box_2">
				<img src="../../static/icon/mine2.png" alt="">
				<view class="text_color">
					我的
				</view>
			</view>
		</view> -->
		<!-- 登陆弹窗组件 -->
		<view v-show='loginAss' class="back-tankuang">
			<login class="loginw" @guanbi='guanbi' />
		</view>

	</view>
</template>

<script>
	import {
		getToken,
		getUserInfo,
		getMajorInfo
	} from '@/common/util/index.js'
	import {
		checkLoginState
	} from '@/api/login.js'
	export default {
		data() {
			return {
				loginState: false, // 登陆状态【默认false未登录】，检测token存在变为true，
				loginAss: getApp().globalData.loginAss,
				username: '登录/注册',
				headimg: '../../static/icon/icon.png',
				imageUrls: getApp().globalData.imaeWd,
				vip: 0, // 暂定“1”是会员，“0”不是会员 【暂时】
				routes: {
					vip: '/pages/mine/vip/vip',
					about: '/pages/mine/about/about',
					feedback: '/pages/mine/feedback/feedback'
				}
			}
		},
		onShow() {
			this.Userinfo = getUserInfo()
		},
		onLoad() {
			if (getToken()) {
				console.log('已经登陆');
				this.loginState = true
				uni.showTabBar()
			}
			this.getInfo()
		},
		methods: {
			getInfo() {
				let user = uni.getStorageSync('userInfos')
				this.username = user.stuName
				this.headimg = '../../static/icon/login_ed.png'
			},
			goIndexPage() {
				uni.navigateTo({
					url: '/pages/index/index'
				})
			},
			goPage(route) {
				if (!getToken()) {
					uni.showToast({
						title: '请先登录',
						icon: 'error',
						duration: 2000
					})
					this.loginState = true
					return
				} else {
					checkLoginState().then((res) => {
						console.log('登陆状态：', res);
						// console.log('前往:', route);
						uni.navigateTo({
							url: route
						})
					}).catch((err) => {
						console.log('err：', err);
						if (err.data.code == 401 && err.data.message == "账号在其他设备登录") {
							uni.showToast({
								title: '登录过期',
								icon: 'error',
								duration: 2000
							})
							this.loginAss = true;
							uni.hideTabBar()
						}
					})
				}

			},
			login() {
				if (!getToken()) {
					this.loginAss = true
					uni.hideTabBar()
				}
			},
			guanbi(value) {
				this.loginAss = value
			},
			reload() {
				// 获取当前页面路由 具体请看该函数的实现
				const url = this.getPageUrl(1)
				uni.reLaunch({
					url,
					success: () => {
						console.log('reload触发了!!!!!! url====>' + url)
					}
				})
			},
			exit() {
				let that = this
				uni.showModal({
					title: '确认退出',
					success: function(res) {
						if (res.confirm) {
							uni.clearStorageSync()
							uni.reLaunch({
								url: '/pages/index/index'
							})
							that.username = '登录/注册'
							that.headimg = '../../static/icon/icon.png'
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})

			},
		},
	}
</script>

<style lang="scss" scoped>
	.bottom_nav_box {
		display: flex;
		position: fixed;
		z-index: 10;
		bottom: 0;
		left: 0;
		height: 100rpx;
		width: 100vw;
		box-shadow: 0 21rpx 47rpx 4rpx rgba(158, 155, 155, 0.1400);
		border-radius: 10rpx 10rpx 0 0;
		font-size: 20rpx;
		font-family: PingFang SC;
		font-weight: bold;
		background: #FFFFFF;

		.bottom_nav_box_1 {
			padding-top: 15rpx;
			margin-left: 220rpx;
			color: #4F5C5E;

			img {
				width: 40rpx;
				height: 40rpx;
			}
		}

		.bottom_nav_box_2 {
			padding-top: 15rpx;
			margin-left: 230rpx;
			color: #0191A0;

			img {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}

	.top_nav_box {
		position: fixed;
		width: 100vw;
		z-index: 10;
		top: 0;
		left: 0;
		background-color: #0191a0;
		padding-top: 90rpx;
		padding-bottom: 30rpx;

		.title {
			text-align: center;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
		}
	}

	.login_wxlogin_btn {
		margin: 70rpx auto 0 auto;
		width: 500rpx;
		height: 80rpx;
		background: #0191A0;
		border-radius: 10rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
		text-align: center;
		line-height: 80rpx;
	}

	.login_phonelogin_btn {
		margin: 20rpx auto 0 auto;
		width: 501rpx;
		height: 81rpx;
		border: 1rpx solid #A6B9BB;
		border-radius: 10rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #A6B9BB;
		text-align: center;
		line-height: 81rpx;
	}

	.login_tip {
		margin-top: 24rpx;
		text-align: center;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #B2B9BA;
	}

	.login_phone {
		text-align: center;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #0191A0;
	}

	.login_title {
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #132B2E;
		text-align: center;
		margin-top: 70rpx;
		margin-bottom: 60rpx;
	}

	.login_icon {
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #132B2E;

		img {
			width: 46rpx;
			height: 46rpx;
			display: inline-block;
			margin-right: 11rpx;
		}

	}

	.login_div_bg {
		position: fixed;
		top: 0;
		left: 0;
		height: 100vh;
		width: 100vw;
		background-color: #969696;
	}

	.login_div {
		padding: 40rpx 0;
		width: 640rpx;
		background-color: white;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}


	.bg {
		// padding-top: 160rpx;
		// box-sizing: border-box;
		// padding-bottom: 170rpx;
		height: 100vh;
		background-color: #f6f6f6;
		overflow-y: hidden;
	}

	.footer {
		position: fixed;
		bottom: 68rpx;
		left: 30rpx;
		width: 690rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		background: #FFFFFF;
		box-shadow: 0px 0px 0px 0px rgba(127, 126, 126, 0.1300);
		border-radius: 10rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #132B2E;
	}

	.section {
		padding: 0 25rpx;
		margin: 30rpx 30rpx 0 30rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 0px 0px rgba(127, 126, 126, 0.1300);
		border-radius: 10rpx;
	}

	.section_item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 35rpx 0;
		border-bottom: 1px solid #E5E5E5;

		.section_item_l {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #132B2E;

			img {
				width: 36rpx;
				height: 36rpx;
				display: inline-block;
				margin-right: 25rpx;
			}
		}

		.section_item_r {
			img {
				width: 15rpx;
				height: 24rpx;
			}
		}
	}



	.header_vip {
		width: auto;
		margin: 40rpx 30rpx 0 30rpx;
		background: linear-gradient(89deg, #F8D7AE 0%, #FBE9D0 37%, #FAD5A9 100%);
		border-radius: 30px 30px 0px 0px;
		display: flex;
	}

	.header_vip_icon {
		width: 118rpx;
		height: 33rpx;
		margin-top: 30rpx;
		margin-left: 30rpx;

		img {
			width: 100%;
			height: 100%;
		}
	}

	.header_vip_text {
		margin-top: 30rpx;
		margin-left: 30rpx;
		margin-bottom: 30rpx;

		.header_vip_text_1 {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #8D5C16;
		}

		.header_vip_text_2 {
			margin-top: 14rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #CEA366;
		}
	}

	.header_vip_btn {
		margin-top: 30rpx;
		margin-left: 100rpx;
		font-size: 24rpx;
		font-weight: bold;
		color: #8D5C16;
		width: 135rpx;
		height: 52rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 1rpx solid #F8D6A8;
		background: linear-gradient(92deg, #FEFCF9 0%, #FEF4E8 100%);
		border-radius: 26px;

		img {
			width: 13rpx;
			height: 21rpx;
			display: inline-block;
			margin-left: 10rpx;
		}
	}


	.header {
		margin-top: 160rpx;
		background-color: #0191a0;
		padding-top: 50rpx;
	}

	.header_user {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 0 30rpx;
	}

	.header_user_left {
		display: flex;
		align-items: center;

		.header_user_icon {
			width: 120rpx;
			height: 120rpx;
			margin-right: 30rpx;

			img {
				width: 100%;
				height: 100%;
			}
		}

		.header_user_username {
			font-size: 34rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
		}
	}

	.header_user_right {
		width: 22rpx;
		height: 40rpx;

		img {
			width: 100%;
			height: 100%;
		}
	}
</style>
